package com.cloud.code.牛客网;

import java.util.ArrayList;
import java.util.List;



public class Test70 {


    public int[] preorderTraversal (TreeNode root) {
        // write code here


        List<Integer> list = new ArrayList<>();

        dfs(root,list);

        int[] ints = list.stream().mapToInt(Integer::intValue).toArray();
        return ints;
    }

    private void dfs(TreeNode root, List<Integer> list) {

        if(root == null){
            return;
        }

        list.add(root.val);
        dfs(root.left,list);
        dfs(root.right,list);

    }
}
